package resultsDatabase;


import java.util.ArrayList;


public class ListOfResults {
	
	private ArrayList<Result> resultsList= new ArrayList<Result>();
	private static volatile ListOfResults instance;

	// This method is called getInstance. It uses a double - locking mechanism
	// to ensure
	// synchronization between threads when accessed so that no more than one
	// instance is created.
	// Finally the instance of the single List of Results is returned.

	public static ListOfResults getInstance() {
		if (instance == null) {
			synchronized (ListOfResults.class) {
				if (instance == null)
					instance = new ListOfResults();
			}
		}
		return instance;
	}
	
	public synchronized void addResult(Result r){
		resultsList.add(r);
		resultsList.trimToSize();
	}
	
	public synchronized ArrayList<Result> getResultsList(){return resultsList;}
	public void reset(){
		resultsList.clear();
	}
}
